import { request } from 'umi';

/**
* get one record by id
*/
export async function getTakeAwayUserOrderById(id: number, params: object = {}) {
    return request<ApiResponse.ResultModel<TakeAwayUserOrderType.TakeAwayUserOrderResponse>>(`/api/takeAwayUserOrder/getById/${id}`, {
        method: 'GET',
        params: params
    });
}

/**
* get all records
*/
export async function getTakeAwayUserOrderAll(params: object = {}) {
    return request<ApiResponse.ResultModel<TakeAwayUserOrderType.TakeAwayUserOrderResponse>>(`/api/takeAwayUserOrder/getAll`, {
        method: 'GET',
        params: params
    });
}

/*
* get records by page
*/
export async function getTakeAwayUserOrderPageList(params: object = {}) {
    return request<PageInfo.PageResponse<TakeAwayUserOrderType.TakeAwayUserOrderResponse>>(`/api/takeAwayUserOrder/getAll`, {
        method: 'GET',
        params: params
    });
}

/*
* update partial field of record
*/
export async function commonUpdate(id: number, fieldName: string, value: string) {
    return request<ApiResponse.ResultModel<TakeAwayUserOrderType.TakeAwayUserOrder>>(`/api/takeAwayUserOrder/PatchById?id=${id}`, {
        method: 'PATCH',
        headers: {
            'Content-Type': 'application/json',
        },
        data: [{
            "id": id,
            "op": "replace",
            "path": `/${fieldName}`,
            "value": value

        }]
    });
}

/*
* update record
*/
export async function updateTakeAwayUserOrder(params: TakeAwayUserOrderType.TakeAwayUserOrderResponse) {
    return request<ApiResponse.ResultModel<boolean>>(`/api/takeAwayUserOrder/put`, {
        method: 'put',
        headers: {
            'Content-Type': 'application/json',
        },
        data: [params],
    });
}

/*
* add one record
*/
export async function addTakeAwayUserOrder(params: TakeAwayUserOrderType.TakeAwayUserOrderResponse) {
    return request<ApiResponse.ResultModel<TakeAwayUserOrderType.TakeAwayUserOrderResponse>>('/api/takeAwayUserOrder/add', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        data: [params],
    });
}

export async function deleteTakeAwayUserOrder(params: DeleteRequest) {
    return request<ApiResponse.ResultModel<boolean>>(`/api/takeAwayUserOrder/delete`, {
        method: 'DELETE',
        headers: {
            'Content-Type': 'application/json',
        },
        data: [params.id],
    });
}
